<!---{
"title": "Building quick-lint-js on macOS from source",
"navTitle": "macOS build"
}--->

<!DOCTYPE html>
<!-- Copyright (C) 2020  Matthew "strager" Glazar -->
<!-- See end of file for extended copyright information. -->
<html>
  <head>
    <%- await include("../../../common-head.ejs.html") %>
    <link href="../../../main.css" rel="stylesheet" />
  </head>
  <body class="side-bar-nav">
    <header><%- await include("../../../common-nav.ejs.html") %></header>

    <main>
      <h1><qljs-icon name="macos" size="29" /> <%= meta.title %></h1>

      <p>
        On macOS, you can build quick-lint-js using one of the following build
        systems:
      </p>
      <ul>
        <li>CMake &amp; Ninja with Xcode CLI tools (recommended)</li>
        <li>
          <a href="#ninja-homebrew"
            >CMake &amp; Ninja with Homebrew Clang/LLVM</a
          >
          (recommended)
        </li>
        <li>CMake &amp; Xcode IDE</li>
        <li><a href="../nix/">Nix</a> (Nix users only)</li>
        <li>
          <a href="../#single-command-build">Single-command build</a> (not
          recommended)
        </li>
      </ul>

      <section id="ninja-homebrew">
        <h2>Building with Homebrew CMake, Ninja, and Clang/LLVM</h2>

        <h3>0. Install Homebrew packages</h3>

        <p>
          Install LLVM, CMake, and Ninja using
          <a href="https://brew.sh/">Homebrew</a> by running the following
          command:
        </p>
        <blockquote>
          <pre><code class="shell-session"><kbd>brew install cmake llvm ninja</kbd></code></pre>
        </blockquote>

        <h3>1. Configure with CMake</h3>

        <p>
          Run the following command to use Homebrew’s version of LLVM and create
          a directory called <code>build</code>:
        </p>
        <blockquote>
          <pre><code class="shell-session"><kbd>PATH=&quot;$(brew --prefix)/opt/llvm/bin:$PATH&quot; \
  CC=clang \
  CXX=clang++ \
  CPPFLAGS=&quot;-I$(brew --prefix)/opt/llvm/include&quot; \
  CXXFLAGS=-D_LIBCPP_DISABLE_AVAILABILITY \
  LDFLAGS=&quot;-L$(brew --prefix)/opt/llvm/lib -L$(brew --prefix)/opt/llvm/lib/c++&quot; \
  cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Debug -S . -B build</kbd></code></pre>
        </blockquote>

        <h3>2. Build</h3>

        <p>
          Run the following command to build the quick-lint-js executable,
          quick-lint-js’ tests, and quick-lint-js’ benchmarks:
        </p>
        <blockquote>
          <pre><code class="shell-session"><kbd>ninja -C build</kbd></code></pre>
        </blockquote>

        <p>If you only want to build the quick-lint-js executable:</p>
        <blockquote>
          <pre><code class="shell-session"><kbd>ninja -C build quick-lint-js</kbd></code></pre>
        </blockquote>

        <p>If you only want to build quick-lint-js’ tests:</p>
        <blockquote>
          <pre><code class="shell-session"><kbd>ninja -C build quick-lint-js-test</kbd></code></pre>
        </blockquote>

        <h3>3. Run</h3>

        <p>Run the following command to run quick-lint-js’ test suite:</p>
        <blockquote>
          <pre><code class="shell-session"><kbd>./build/test/quick-lint-js-test</kbd></code></pre>
        </blockquote>

        <p>If you want to run the quick-lint-js program:</p>
        <blockquote>
          <pre><code class="shell-session"><kbd>./build/quick-lint-js --help</kbd></code></pre>
        </blockquote>
      </section>

      <!-- TODO(strager): Document how to build with Xcode's CLI tools. -->
      <!-- TODO(strager): Document how to build with the Xcode IDE. -->
    </main>

    <footer><%- await include("../../../common-footer-nav.ejs.html") %></footer>
  </body>
</html>

<!--
quick-lint-js finds bugs in JavaScript programs.
Copyright (C) 2020  Matthew "strager" Glazar

This file is part of quick-lint-js.

quick-lint-js is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

quick-lint-js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with quick-lint-js.  If not, see <https://www.gnu.org/licenses/>.
-->
